package com.example.course_mangger_system.controller;

import com.example.course_mangger_system.entity.Course;
import com.example.course_mangger_system.service.CourseService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 课程
 * @author: hyj
 * @date: 2023/11/25 15:53
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    @Resource
    private CourseService courseService;

    /**
     * 添加
     *
     * @param course
     * @return
     */
    @PostMapping("/save")
    public int save(@RequestBody Course course) {

        return courseService.save(course);
    }

    /**
     * 删除
     *
     * @param course
     * @return
     */
    @PostMapping("/delete")
    public int delete(@RequestBody Course course) {
        if (course.getCourseCode() == null) {
            return 0;
        }
        return courseService.delete(course.getCourseCode());
    }

    /**
     * 修改
     *
     * @param course
     * @return
     */
    @PostMapping("/update")
    public int update(@RequestBody Course course) {
        if (course.getCourseCode() == null) {
            return 0;
        }
        return courseService.update(course);
    }

    /**
     * 查询
     *
     * @param course
     * @return
     */
    @PostMapping("/list")
    public List<Course> list(@RequestBody Course course) {
        return courseService.list(course);
    }


    @PostMapping("/getById")
    public Course getById(@RequestBody Course course) {
        if (course.getCourseCode() == null) {
            return null;
        }
        return courseService.getById(course.getCourseCode());
    }
}
